////////////////////////////////////////////////////////////////////
//                          _ooOoo_                               //
//                         o8888888o                              //
//                         88" . "88                              //
//                         (| ^_^ |)                              //
//                         O\  =  /O                              //
//                      ____/`---'\____                           //
//                    .'  \\|     |//  `.                         //
//                   /  \\|||  :  |||//  \                        //
//                  /  _||||| -:- |||||-  \                       //
//                  |   | \\\  -  /// |   |                       //
//                  | \_|  ''\---/''  |   |                       //
//                  \  .-\__  `-`  ___/-. /                       //
//                ___`. .'  /--.--\  `. . ___                     //
//              ."" '<  `.___\_<|>_/___.'  >'"".                  //
//            | | :  `- \`.;`\ _ /`;.`/ - ` : | |                 //
//            \  \ `-.   \_ __\ /__ _/   .-` /  /                 //
//      ========`-.____`-.___\_____/___.-`____.-'========         //
//                           `=---='                              //
//      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //
//         佛祖保佑          永无BUG         永不修改              //
////////////////////////////////////////////////////////////////////
package com.financial.sys.controller.system;

import com.financial.common.vo.Result;
import com.financial.model.pojo.TSystemDictionary;
import com.financial.model.pojo.TSystemDictionaryItem;
import com.financial.sys.query.LoginLogQuery;
import com.financial.sys.service.register.LogLoginService;
import com.financial.sys.service.system.TSystemDictionaryItemService;
import com.financial.sys.service.system.TSystemDictionaryService;
import com.financial.sys.vo.repayment.TSystemDictionaryItemQuery;
import com.financial.sys.vo.repayment.TSystemDictionaryQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: 周未
 * @Description:
 * @create 10:58 2020/2/20
 */
@Api (tags = "数据字典", value = "")
@RestController
@RequestMapping ("/system")
public class SystemController {

	@Autowired
	TSystemDictionaryItemService tSystemDictionaryItemService;
	@Autowired
	TSystemDictionaryService tSystemDictionaryService;
	@Autowired
	LogLoginService logLoginService;

	@ApiOperation (value = "所有字典项")
	@GetMapping ("/dictionaryItem/getAll")
	public Result dictionaryItemGetAll() {
		return Result.ok().data(tSystemDictionaryItemService.list(null));
	}

	@ApiOperation (value = "字典项查询")
	@PostMapping ("/dictionaryItem/query")
	public Result dictionaryItemQuery(TSystemDictionaryItemQuery tSystemDictionaryItemQuery) {
		return Result.ok().data(tSystemDictionaryItemService.query(tSystemDictionaryItemQuery));
	}

	@ApiOperation (value = "修改字典项")
	@PostMapping ("/dictionaryItem/update")
	public Result dictionaryItemUpdate(TSystemDictionaryItem tSystemDictionaryItem) {
		tSystemDictionaryItemService.updateById(tSystemDictionaryItem);
		return Result.ok();
	}

	@ApiOperation (value = "新增字典项")
	@PostMapping ("/dictionaryItem/add")
	public Result dictionaryItemAdd(TSystemDictionaryItem tSystemDictionaryItem) {
		tSystemDictionaryItemService.save(tSystemDictionaryItem);
		return Result.ok();
	}

	@ApiOperation (value = "所有字典")
	@PostMapping ("/dictionary/getAll")
	public Result dictionaryGetAll() {
		return Result.ok().data(tSystemDictionaryService.list(null));
	}

	@ApiOperation (value = "字典查询")
	@PostMapping ("/dictionary/query")
	public Result dictionaryQuery(TSystemDictionaryQuery tSystemDictionaryQuery) {
		return Result.ok().data(tSystemDictionaryService.query(tSystemDictionaryQuery));
	}

	@ApiOperation (value = "修改字典")
	@PostMapping ("/dictionary/update")
	public Result dictionaryUpdate(TSystemDictionary tSystemDictionary) {
		tSystemDictionaryService.updateById(tSystemDictionary);
		return Result.ok();
	}

	@ApiOperation (value = "新增字典项")
	@PostMapping ("/dictionary/add")
	public Result dictionaryAdd(TSystemDictionary tSystemDictionary) {
		tSystemDictionaryService.save(tSystemDictionary);
		return Result.ok();
	}

	@ApiOperation (value = "登录日志查询")
	@PostMapping ("/loginlog/query")
	public Result loginlogQuery(LoginLogQuery loginLogQuery) {
//		QueryWrapper queryWrapper = new QueryWrapper();
//		IPage iPage = new Page();
//		if (!StringUtils.isEmpty(loginLogQuery)) {
//			if (loginLogQuery.getCurrentPage() != null) {
//				iPage.setCurrent(loginLogQuery.getCurrentPage());
//			}
//			if (loginLogQuery.getPageSize() != null) {
//				iPage.setSize(loginLogQuery.getPageSize());
//			}
//			if (loginLogQuery.getUsername() != null) {
//				queryWrapper.eq("username", loginLogQuery.getUsername());
//			}
//			if (loginLogQuery.getLoginResult() != null) {
//				queryWrapper.eq("login_result", loginLogQuery.getLoginResult());
//			}
//			if (loginLogQuery.getBeginDate() != null && loginLogQuery.getBeginDate() != "00:00:00") {
//				queryWrapper.ge("create_time", loginLogQuery.getBeginDate());
//			}
//			if (loginLogQuery.getEndDate() != null && loginLogQuery.getEndDate() != "23:59:59") {
//				queryWrapper.le("create_time", loginLogQuery.getEndDate());
//			}
//		}
//		IPage page = logLoginService.page(iPage, queryWrapper);
//		Map<String, Object> map = new HashMap<>();
//		map.put("listData", page.getRecords());
		return Result.ok().data(logLoginService.selectLoginLog(loginLogQuery));
	}
}
